import 'package:flutter/material.dart';
import 'res/ListData.dart';

void main() {
  runApp(MyApp());
}

//自定义组件
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // MaterialApp是根组件
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('dynamic_create_listview'),
        ),
        body: HomeContent(),
      ),
      theme: ThemeData(primaryColor: Colors.blue),
    );
  }
}

//body内容组件
class HomeContent extends StatelessWidget {
  List<Widget> _getWidgetData() {
    List<Widget> tempList = listData.map((value) {
      return ListTile(
        title: Text(value["title"]),
        subtitle: Text(value["author"]),
      );
    }).toList();
    return tempList;
  }

  @override
  Widget build(BuildContext context) {
    return ListView(
      //可以有多种组件Container, Image,ListTile等
      children: this._getWidgetData(),
    );
  }
}
